﻿using UnityEngine;
using System.Collections;

public class Cannon : MonoBehaviour {

    //public Rigidbody missilePrefab = null;
    public GameObject missilePrefab = null;


    public float interval = 2f;

    private float beginningTime = 0;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        
        if (beginningTime == 0)
            beginningTime = Time.time;

         if(beginningTime != 0)
         {
            if (Time.time >= beginningTime + interval)
            {
                //Rigidbody missile = Instantiate(missilePrefab, transform.position, transform.rotation) as Rigidbody;
                GameObject missile = Instantiate(missilePrefab, transform.position, transform.rotation) as GameObject;

                //missile.velocity = transform.TransformDirection(Vector3.right * 10);
                beginningTime = 0;
                    //clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
            //clone.velocity = transform.TransformDirection(Vector3.forward * 10);
            }
        }

	}
}
